package com.yan;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;


/**
 * @author WangYan
 * @description:
 * @date 2021/7/5 19:20
 */
public class ConsumerApp {
    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RabbitConfig.class);
        RabbitTemplate template = context.getBean(RabbitTemplate.class);

        while (true) {
            Message message = template.receive("queue.anno.name.yan");
            if (message == null) {
                Thread.sleep(1000);
            } else {
                //        String contentEncoding = "utf-8";
                String contentEncoding = message.getMessageProperties().getContentEncoding();
                String msg = new String(message.getBody(), contentEncoding);
                System.out.println("----ConsumerApp-----" + msg);
            }
        }

//        context.close();
    }
}
